from datetime import datetime
from typing import List

import pandas as pd

from app.models.po.hanfan.hanfan_new_predict_po import HanfanNewPredictPO
from app.models.po.luzha.luzha_predict_po import LuzhaPredictPO
from app.services.business import hanfan_biz_service, gaolu_biz_service
from app.services.business.gaolu_diagnose import gaolu_diagnose_service
from app.services.business.hanfan import luzha_biz_service
from app.services.chart.Line import Line
from app.utils import date_util, simple_util, string_util
from datetime import timedelta


class GaoluDiagnoseScore(Line):
    """
    钒含量数据表
    """
    def get_zero(self,v):
        if v is None: return 0
        return v

    def generate(self, start, end):
        # if string_util.is_empty(start) or string_util.is_empty(end):
        #     base = date_util.get_start_of_hour(datetime.now())
        #     start = base - timedelta(days=1)
        #     end = base

        yAxis_array = [
            {
                "name": "高炉分数",
                "type": 'value'
            }
        ]

        gaolu_diagnose_records: list = gaolu_diagnose_service.get_score(start, end)
        data_x = [date_util.date_time_to_str(record['date_time'], "%Y%m%d") for record in gaolu_diagnose_records]

        y = [round(self.get_zero(record.get("score")), 2) for record in gaolu_diagnose_records]

        gaolu_predict_records: list = gaolu_biz_service.get_daily_score_by_range(start, end)
        gaolu_predict_dict = {date_util.date_time_to_str(record['date_time'], "%Y%m%d"): record['score']
                              for record in gaolu_predict_records}

        y2 = [gaolu_predict_dict.get(x, 0) for x in data_x]

        data_y_array = [dict(name="大数据分数", y=y, type="line"),
                        dict(name="专家分数", y=y2, type="line")]

        return dict(x=data_x,
                    tooltip={
                        "trigger": 'axis'
                    },
                    y_array=data_y_array, desc="高炉分数", multiSerie=True,
                    yAxis_array=yAxis_array)
